package com.shengwei.truck.driver.view.adapter.task;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.bean.MyConstant;
import com.shengwei.truck.driver.bean.task.OrderItem;
import com.shengwei.truck.driver.bean.task.TaskItem;
import com.shengwei.truck.driver.databinding.TaskItemListBinding;
import com.shengwei.truck.driver.utils.DateTimeUtils;
import com.shengwei.truck.driver.view.adapter.BaseAdapter;
import java.util.List;

/**
 * 新订单列表，以后要优化：同任务列表合并成一个类
 */
public class OrderListAdapter extends BaseAdapter<OrderListAdapter.ViewHolder> {
    private List<OrderItem> mDataList;
    public OrderListAdapter(Context context) {
        super(context);
    }
    @Override
    public void notifyDataSetChanged(List<TaskItem> dataList) {

    }
    /**
     * 更新订单列表item数据
     * @param dataList
     */
    @Override
    public void notifyOrderItemChange(List<OrderItem> dataList) {
        this.mDataList = dataList;
        super.notifyDataSetChanged();
    }
    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.size();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        TaskItemListBinding taskItemListBinding = DataBindingUtil.inflate(getInflater(),R.layout.task_item_list,parent,false);
        // 订单列表没有共享和指派标签
        taskItemListBinding.imvForward.setVisibility(View.GONE);
        return new ViewHolder(taskItemListBinding);
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        TaskItemListBinding viewDataBinding = (TaskItemListBinding) holder.viewDataBinding;
        OrderItem orderItem = mDataList.get(position);
       // orderItem.uaName = MyConstant.testCustomName; //要恢复
        viewDataBinding.setTaskItem(orderItem);
        //以下两个字段要单独赋值，因为订单列表项和任务列表项公用的是一个布局，显示的内容有差别
        viewDataBinding.tvTaskNoLabel.setText(R.string.order_num2);
        viewDataBinding.tvTaskNoValue.setText(orderItem.planNo);
        viewDataBinding.tvPublishTime.setText(DateTimeUtils.timeStampToDateString(orderItem.createTime));
    }
    static class ViewHolder extends RecyclerView.ViewHolder {
        ViewDataBinding viewDataBinding;
        public ViewHolder(ViewDataBinding viewDataBinding) {
            super(viewDataBinding.getRoot());
            this.viewDataBinding = viewDataBinding;
        }
    }
}
